package com.aiobc.business.personalcenter.contoller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.aiobc.business.personalcenter.domain.DataCollectionLog;
import com.aiobc.business.personalcenter.service.DataCollectionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aiobc.common.log.annotation.Log;
import com.aiobc.common.log.enums.BusinessType;
import com.aiobc.common.security.annotation.PreAuthorize;

import com.aiobc.common.core.web.controller.BaseController;
import com.aiobc.common.core.web.domain.AjaxResult;
import com.aiobc.common.core.utils.poi.ExcelUtil;
import com.aiobc.common.core.web.page.TableDataInfo;

/**
 * 数据收藏记录Controller
 * 
 * @author zhangcan
 * @date 2021-10-21
 */
@RestController
@RequestMapping("/collection")
public class DataCollectionLogController extends BaseController
{
    @Autowired
    private DataCollectionLogService dataCollectionLogService;

    /**
     * 查询数据收藏记录列表
     */
    @PreAuthorize(hasPermi = "system:log:list")
    @GetMapping("/list")
    public TableDataInfo list(DataCollectionLog dataCollectionLog)
    {
        startPage();
        List<DataCollectionLog> list = dataCollectionLogService.selectDataCollectionLogList(dataCollectionLog);
        return getDataTable(list);
    }

    /**
     * 导出数据收藏记录列表
     */
    @PreAuthorize(hasPermi = "system:log:export")
    @Log(title = "数据收藏记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCollectionLog dataCollectionLog) throws IOException
    {
        List<DataCollectionLog> list = dataCollectionLogService.selectDataCollectionLogList(dataCollectionLog);
        ExcelUtil<DataCollectionLog> util = new ExcelUtil<DataCollectionLog>(DataCollectionLog.class);
        util.exportExcel(response, list, "数据收藏记录数据");
    }

    /**
     * 获取数据收藏记录详细信息
     */
    @PreAuthorize(hasPermi = "system:log:query")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") String logId)
    {
        return AjaxResult.success(dataCollectionLogService.selectDataCollectionLogById(logId));
    }

    /**
     * 新增数据收藏记录
     */
    @PreAuthorize(hasPermi = "system:log:add")
    @Log(title = "数据收藏记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCollectionLog dataCollectionLog)
    {
        return toAjax(dataCollectionLogService.insertDataCollectionLog(dataCollectionLog));
    }

    /**
     * 修改数据收藏记录
     */
    @PreAuthorize(hasPermi = "system:log:edit")
    @Log(title = "数据收藏记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCollectionLog dataCollectionLog)
    {
        return toAjax(dataCollectionLogService.updateDataCollectionLog(dataCollectionLog));
    }

    /**
     * 删除数据收藏记录
     */
    @PreAuthorize(hasPermi = "system:log:remove")
    @Log(title = "数据收藏记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable String[] logIds)
    {
        return toAjax(dataCollectionLogService.deleteDataCollectionLogByIds(logIds));
    }
}
